<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增任务指令')" />
    <th:block th:include="include :: bootstrap-fileinput-css" />

    <style>
        .form-horizontal .form-group {
            margin-right: 0px;
            margin-left: 0px;
        }
        .input-group .form-control{
            width: 60%;
        }
    </style>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-centralTaskCmd-add">
            <input name="resourcePath"  type="hidden" >
            <div class="form-group">    
                <label class="col-sm-3 control-label is-required">任务指令名称：</label>
                <div class="col-sm-8">
                    <input name="name" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">操作类型：</label>
                <div class="col-sm-8">
                    <select name="type" class="form-control m-b" th:with="type=${@dict.getType('central_operation_type')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">调用对象：</label>
                <div class="col-sm-8">
                    <input class="form-control" type="text" name="executable" id="executable" >
                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> Bean调用示例：ryTask.ryParams('ry')</span>
                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> Class类调用示例：com.ruoyi.quartz.task.RyTask.ryParams('ry')</span>
                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 参数说明：支持字符串，布尔类型，长整型，浮点型，整型</span>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">指令类型：</label>
                <div class="col-sm-8">
                    <select name="commandType" class="form-control m-b">
                        <option value="">请选择</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">模板：</label>
                <div class="col-sm-8">
                    <textarea name="template" class="form-control"></textarea>
                </div>
            </div>
<!--            <div class="form-group">    -->
<!--                <label class="col-sm-3 control-label">资源路径：</label>-->
<!--                <div class="col-sm-8">-->
<!--                    <input name="resourcePath" class="form-control" type="text">-->
<!--                </div>-->
<!--            </div>-->

            <div class="form-group">
                <label class="col-sm-3 control-label">资源路径：</label>
                <div class="col-sm-8">
                    <div class="form-group">
                        <div class="file-loading">
                            <input id="singleFile" name="file" type="file" >
                        </div>
                    </div>


<!--                    <div class="layui-upload-drag" id="upload">-->
<!--                        <i class="layui-icon"></i>-->
<!--                        <p>点击上传，或将文件拖拽到此处</p>-->
<!--                        <div class="layui-hide" id="uploadDemoView">-->
<!--                            <hr>-->
<!--                            <img src="" alt="上传成功后渲染" style="max-width: 196px">-->
<!--                        </div>-->
<!--                    </div>-->
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-3 control-label">权重：</label>
                <div class="col-sm-8">
                    <input name="weight" class="form-control input-number" type="text" >
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">描述：</label>
                <div class="col-sm-8">
                    <textarea name="remark" class="form-control"></textarea>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <script th:inline="javascript">
        var prefix = ctx + "central/centralTaskCmd"
        $.commonBusiness.getIncrementWeight(prefix)
        $("[name=weight]").inputSpinner();
        $("#form-centralTaskCmd-add").validate({
            focusCleanup: true
        });
        let orderToUpload = false
        function submitHandler() {
            const filesCount = $('#singleFile').fileinput('getFilesCount');

            if(filesCount){
                orderToUpload = true
                $("#singleFile").fileinput('upload');
            }else{
                if ($.validate.form()) {
                    $.operation.insert(prefix, $.common.formToJSON());
                }
            }
        }

        $(document).ready(function () {
            // 单图上传
            $("#singleFile").fileinput({
                language: 'zh', //设置语言
                uploadUrl: ctx + 'common/upload',
                //allowedFileTypes:[],
                maxFileCount: 1,
                autoReplace: true,
                enctype: 'multipart/form-data',
                validateInitialCount:true,
                validateInitialCount:true,
                msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！",
                uploadExtraData(){
                    return {directoryName:"sources/",byDate:false}
                }
            }).on('fileuploaded', function (event, data, previewId, index) {
                var rsp = data.response;
                $("[name=resourcePath]").val(rsp.fileName);
                if(orderToUpload){
                    if ($.validate.form()) {
                        $.operation.insert(prefix, $.common.formToJSON());
                    }
                }
                console.log("$(\"[name=resourcePath]\").val",$("[name=resourcePath]").val())
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
                $("[name=resourcePath]").val('');
            })
        });

        //
        // layui.use(['upload', 'element', 'layer'], function() {
        //     var $ = layui.jquery
        //         , upload = layui.upload
        //         , element = layui.element
        //         , layer = layui.layer;
        //
        //     //拖拽上传
        //     upload.render({
        //         elem: '#upload',
        //         accept:'file',//支持上传所有文件
        //         acceptMime:'',
        //         url: 'https://httpbin.org/post', //此处用的是第三方的 http 请求演示，实际使用时改成您自己的上传接口即可。
        //         exts:'',//只允许上传的后缀文件
        //         auto:true,//是否自动上传
        //         multiple:false,//不支持多文件上传
        //         number:1,//上传数量限制
        //         drag:true,//支持拖拽上传文件
        //         done: function(res){
        //             console.log(res)
        //         }
        //     });
        // })
    </script>
</body>
</html>